package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingElderDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.ContractVo;
import com.zzyl.vo.NursingProjectVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> selectByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name,status);
        PageResponse<NursingProjectVo> page = PageResponse.of(nursingProjects,NursingProjectVo.class);
        return page;
    }

    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.add(nursingProject);
    }

    @Override
    public NursingProjectVo getById(Long id) {
        NursingProject  nursingProject = nursingProjectMapper.getById(id);
        if (nursingProject != null){
            NursingProjectVo nursingProjectVo = new NursingProjectVo();
            BeanUtils.copyProperties(nursingProject, nursingProjectVo);
            return nursingProjectVo;
        }
        return null;
    }

    @Override
    public void del(Long id) {
        nursingProjectMapper.del(id);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
        nursingProjectMapper.putStatus(id,status);
    }

    @Override
    public List<NursingProjectVo> all() {
        return nursingProjectMapper.all();
    }

    @Override
    public void updete(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.updete(nursingProject);
    }


}
